/**
 * ArticlePersistenceServiceImpl.java 上午9:42:53 2012-5-1
 * Cyber Information Technology Co.,Ltd.
 *   
 *   http://www.citchina.cn
 *   citchina.org@gmail.com
 */
package cn.cit.wcif.article.persistence.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import cn.cit.wcif.article.api.persistence.IArticleEntity;
import cn.cit.wcif.article.api.persistence.IArticlePersistenceService;
import cn.cit.wcif.article.persistence.jpa.entity.ArticleEntityImpl;

/**
 * @author Jonathan
 * @version 1.0
 * 
 */
@Repository
public class ArticlePersistenceServiceImpl implements
		IArticlePersistenceService {

	@PersistenceContext
	private EntityManager em;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.cit.wcif.article.api.persistence.IArticlePersistenceService#persistArticle
	 * (cn.cit.wcif.article.api.persistence.IArticleEntity)
	 */
	@Override
	public IArticleEntity persistArticle(IArticleEntity entity) {
		IArticleEntity article = new ArticleEntityImpl();
		article.setBackReason(entity.getBackReason());
		article.setChID(entity.getChID());
		article.setContent(entity.getContent());
		article.setContentKey(entity.getContentKey());
		article.setContentName(entity.getContentName());
		article.setContentState(entity.getContentState());
		article.setContentZhaiyao(entity.getContentZhaiyao());
		article.setId(entity.getId());
		article.setInfoSrc(entity.getInfoSrc());
		article.setIntroduction(entity.getIntroduction());
		article.setLang(entity.getLang());
		article.setPublishDate(entity.getPublishDate());
		article.setPublishUserID(entity.getPublishUserID());
		article.setRecommend(entity.getRecommend());
		article.setRecommendTime(entity.getRecommendTime());
		article.setUpdateTime(entity.getUpdateTime());
		article.setUpdateUserID(entity.getUpdateUserID());
		em.persist(article);
		return article;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.cit.wcif.article.api.persistence.IArticlePersistenceService#mergeArticle
	 * (cn.cit.wcif.article.api.persistence.IArticleEntity)
	 */
	@Override
	public IArticleEntity mergeArticle(IArticleEntity entity) {
		IArticleEntity article = new ArticleEntityImpl();
		article.setBackReason(entity.getBackReason());
		article.setChID(entity.getChID());
		article.setContent(entity.getContent());
		article.setContentKey(entity.getContentKey());
		article.setContentName(entity.getContentName());
		article.setContentState(entity.getContentState());
		article.setContentZhaiyao(entity.getContentZhaiyao());
		article.setId(entity.getId());
		article.setInfoSrc(entity.getInfoSrc());
		article.setIntroduction(entity.getIntroduction());
		article.setLang(entity.getLang());
		article.setPublishDate(entity.getPublishDate());
		article.setPublishUserID(entity.getPublishUserID());
		article.setRecommend(entity.getRecommend());
		article.setRecommendTime(entity.getRecommendTime());
		article.setUpdateTime(entity.getUpdateTime());
		article.setUpdateUserID(entity.getUpdateUserID());
		em.merge(article);
		return article;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.cit.wcif.article.api.persistence.IArticlePersistenceService#
	 * listTop5Articles()
	 */
	@Override
	public List<IArticleEntity> listTop5Articles() {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.cit.wcif.article.api.persistence.IArticlePersistenceService#pageArticles
	 * (int, int)
	 */
	@Override
	public List<IArticleEntity> pageArticles(int pageSize, int perPage) {
		// TODO Auto-generated method stub
		return null;
	}

}
